function conv(input, origine, prix){	

	var valeur = input.value;
	inputs = document.getElementsByTagName("input");
	
	if(origine=="ppublic")	{
	
		lmarge = Math.round((parseFloat(valeur)-parseFloat(prix))*100);
		taux = Math.round(((1-(parseFloat(prix)/parseFloat(valeur)))*100)*10000);
		ppublicttc= Math.round((parseFloat(valeur)*1.196)*100);
		
		if(isNaN(taux)) { inputs["taux"].value = 'Impossible'; } else { inputs["taux"].value = taux/10000; }
		if(isNaN(lmarge)) { inputs["marge"].value = 'Impossible'; } else { inputs["marge"].value = lmarge/100; }
		if(isNaN(ppublicttc)) { inputs["ppublicttc"].value = 'Impossible'; } else { inputs["ppublicttc"].value = ppublicttc/100; }
	
	}else if(origine=="taux")	{
	
		ppublic = Math.round((parseFloat(prix)/(1-(parseFloat(valeur)/100)))*100);
		lmarge = Math.round(((parseFloat(ppublic)/100)-parseFloat(prix))*100);
		ppublicttc = Math.round(((parseFloat(ppublic)/100)*1.196)*100);
		
		
		if(Math.round(valeur) >= 100){
			inputs["ppublic"].value = 'Impossible';
			inputs["marge"].value = 'Impossible';
			inputs["ppublicttc"].value = 'Impossible';
		}else{
			if(isNaN(ppublic)) { inputs["ppublic"].value = 'Impossible'; } else { inputs["ppublic"].value = ppublic/100; }
			if(isNaN(lmarge)) { inputs["marge"].value = 'Impossible'; } else { inputs["marge"].value = lmarge/100; }
			if(isNaN(ppublicttc)) { inputs["ppublicttc"].value = 'Impossible'; } else { inputs["ppublicttc"].value = ppublicttc/100; }
		}
	
	}else if(origine=="marge"){
		
		ppublic = Math.round((((parseFloat(valeur)-1)+(parseFloat(prix)-1))+2)*100);
		taux = Math.round((1-(parseFloat(prix/ppublic))*10000)*10000);
		ppublicttc = Math.round(((parseFloat(ppublic)/100)*1.196)*100);
		
		if(isNaN(ppublic)) { inputs["ppublic"].value = 'Impossible'; } else { inputs["ppublic"].value = ppublic/100; }
		if(isNaN(taux)) { inputs["taux"].value = 'Impossible'; } else { inputs["taux"].value = taux/10000; }
		if(isNaN(ppublicttc)) { inputs["ppublicttc"].value = 'Impossible'; } else { inputs["ppublicttc"].value = ppublicttc/100; }
	
	}else if(origine=="ppublicttc"){
		
		ppublic = Math.round((parseFloat(valeur)/1.196)*100);
		taux = Math.round((1-(parseFloat(prix/ppublic))*10000)*10000);
		lmarge = Math.round(((parseFloat(ppublic)/100)-parseFloat(prix))*100);
		
		if(isNaN(ppublic)) { inputs["ppublic"].value = 'Impossible'; } else { inputs["ppublic"].value = ppublic/100; }
		if(isNaN(taux)) { inputs["taux"].value = 'Impossible'; } else { inputs["taux"].value = taux/10000; }
		if(isNaN(lmarge)) { inputs["marge"].value = 'Impossible'; } else { inputs["marge"].value = lmarge/100; }
	
	}
}

function taille(obj) {
	return obj.offsetHeight + obj.offsetTop;
}

function placepied() {
	if (document.getElementById!=null) {
		var FO = document.getElementById("footer");
		var CO = document.getElementById("content")
		var LE = document.getElementById("left");
		var RI = document.getElementById("right");
		var maxheight = Math.max(taille(CO),taille(LE));
		if(RI) maxheight = Math.max(maxheight,taille(RI));
			maxheight = parseFloat(maxheight)+50;
			with (FO.style) {
				position="absolute";
				top=maxheight+"px";
				marginRight="0";
				marginLeft="0";
				width="100%";
				background="url(medias/foot2.png) repeat-x left bottom";}
	}
}

function hideselect(){
	CH = document.getElementById('choix');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'hidden';
	}
	CH = document.getElementById('panierlivraison');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'hidden';
	}
	CH = document.getElementById('rechmar');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'hidden';
	}
}

function unhideselect(){
	CH = document.getElementById('choix');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'visible';
	}
	CH = document.getElementById('panierlivraison');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'visible';
	}
	CH = document.getElementById('rechmar');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].style.visibility = 'visible';
	}
}

function hover(obj){
	hideselect();
  UL = obj.getElementsByTagName('ul');
  if(UL.length > 0){
    sousMenu = UL[0].style;
    if(sousMenu.display == 'none' || sousMenu.display == ''){ sousMenu.display = 'block'; }
  }
	
}

function out(obj){
	unhideselect();
  UL = obj.getElementsByTagName('ul');
  if(UL.length > 0){
    sousMenu = UL[0].style;
    if(sousMenu.display != 'none' && sousMenu.display != ''){ sousMenu.display = 'none'; }
  }
	
}

function rechin(obj){
 	if(obj.value == 'Votre recherche') obj.value = '';
}

function rechout(obj){
 	if(obj.value == '') obj.value = 'Votre recherche';
}

function marqselect(id, form){
	var count=0;
	for (i in marq[id]){
		var optionName = new Option(marq[id][i],i, false, false);
		form.selecmar2.options[count++] = optionName;
	}
}

function marqadd(id, form){
	while (form.selecmar2.options.length) form.selecmar2.options[0] = null;
	if ((typeof marq[id]) == "undefined") id = '1';
	form.selecmar2.disabled=false;
	if (id == "-1") form.selecmar2.disabled=true;
	marqselect(id, form);
}

function rubselect(id, form){
	var count=0;
	for (i in rub[id]){
		var optionName = new Option(rub[id][i],i, false, false);
		form.selecrub2.options[count++] = optionName;
	}
}

function rubadd(id, form){
	while (form.selecrub2.options.length) form.selecrub2.options[0] = null;
	if ((typeof rub[id]) == "undefined") id = '1';
	form.selecrub2.disabled=false;
	if (id == "-1") form.selecrub2.disabled=true;
	rubselect(id, form);
}

function changeurl(id, page){
	if (id != 0){
		document.getElementById('conteneur').style.display = 'none';
		location.href = page;
	}
}

function changeurl2(id, page){
	if (id != 0){
		window.open(page,'catalogue','toolbar=1, location=1, directories=1, status=1, scrollbars=1, resizable=1, copyhistory=1, menuBar=1')
	}
}

function apanier(id){
	var page = "ajout-panier.php?num=" + document.getElementById(id.name.replace('nb','ref')).value + "&nb=" + id.value;
	location.href = page;
}


	
window.onload = function() {
  if(document.all){
	  LI = document.getElementById('menu').getElementsByTagName('li');
	  nLI = LI.length;
	  for(i=0; i < nLI; i++){
	    LI[i].onmouseover = function(){ hover(this); }
	    LI[i].onmouseout = function(){ out(this); }
	  }
  }

  if(marq){
	  document.getElementById('selecmar1').onchange = function(){ marqadd(this.options[this.selectedIndex].value, this.form); }
	  document.getElementById('selecmar2').onchange = function(){ changeurl(this.selectedIndex, this.options[this.selectedIndex].value); }
	  document.getElementById('selecmar1').options[0].selected = true;
		document.getElementById('selecmar2').disabled = true;
	}
	
  if(rub){
	  document.getElementById('selecrub1').onchange = function(){ rubadd(this.options[this.selectedIndex].value, this.form); }
	  document.getElementById('selecrub2').onchange = function(){ changeurl2(this.selectedIndex, this.options[this.selectedIndex].value); }
	  document.getElementById('selecrub1').options[0].selected = true;
		document.getElementById('selecrub2').disabled = true;
	}
	
	CH = document.getElementById('choix');
	if(CH){
		SL = CH.getElementsByTagName('select')[0].onchange = function(){ changeurl(1, this.options[this.selectedIndex].value); }
	}
	
	CH = document.getElementById('choixa');
	if(CH){
		CH.style.visibility = 'visible';
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].onchange = function(){ changeurl(this.selectedIndex, this.options[this.selectedIndex].value); }
	}
	
	CH = document.getElementById('panierlivraison');
	if(CH){
		SL = CH.getElementsByTagName('select');
		for(i=0; i < SL.length; i++) SL[i].onchange = function(){ changeurl(1, this.options[this.selectedIndex].value); }
	}
	
	CH = document.getElementById('prodimg');
	if(CH){
		SL = CH.getElementsByTagName('a');
		for(i=0; i < SL.length; i++) SL[i].onclick = function(){
			window.open('popup.php?file=' + this.href, 'Agrandissement', 'toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=1,width=400,height=400');
			return(false); }
	}
	
	CH = document.getElementById('comparapn');
	if(CH){
		SL = CH.getElementsByTagName('a');
		for(i=0; i < SL.length; i++) SL[i].onclick = function(){ return(true); }
	}

	
	document.getElementById('rech').onfocus = function(){ rechin(this); }
	document.getElementById('rech').onblur = function(){ rechout(this); }
	
	placepied();
}

window.onresize = function() {
	placepied();
}